package com.yanqu.road.server.pb;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.banquet.*;
import com.yanqu.road.entity.banquet.cross.CrossBanquetData;
import com.yanqu.road.entity.banquet.cross.CrossBanquetMember;
import com.yanqu.road.entity.banquet.cross.CrossFeastPartyTempData;
import com.yanqu.road.entity.banquet.invitation.BanquetMarryInvitation;
import com.yanqu.road.entity.banquet.UserCrossBanquetData;
import com.yanqu.road.entity.enums.eBanquetInfoType;
import com.yanqu.road.entity.enums.eBanquetType;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.bussiness.player.UserBeautyBussiness;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.pb.banquet.CrossBanquetProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.manger.banquet.BanquetConfigMgr;
import com.yanqu.road.server.manger.banquet.BanquetMgr;
import com.yanqu.road.server.manger.banquet.CrossBanquetMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;
import java.util.Map;

public class BanquetPb {

	public static BanquetProto.BanquetPopRewardSync.Builder parseBanquetFeastRewardListResp(Map<String,Map<Integer,UserBanquetFeastReward>> rewardInfoMap,int banquetType,boolean syncReward){
		BanquetProto.BanquetPopRewardSync.Builder msg = BanquetProto.BanquetPopRewardSync.newBuilder();
		for(String banquetId : rewardInfoMap.keySet()){
			Map<Integer,UserBanquetFeastReward> infoMap = rewardInfoMap.get(banquetId);
			BanquetProto.BanquetPopRewardTemp.Builder banquetTemp = BanquetProto.BanquetPopRewardTemp.newBuilder();
			banquetTemp.setBanquetId(banquetId);
			if(banquetType == eBanquetType.ServerFeastBanquet.getValue()){
				CrossFeastPartyTempData tempData = BanquetMgr.getCrossFeastPartyTempDataMap().get(banquetId);
				if (tempData == null) {
					continue;
				}
				banquetTemp.setMemNum(tempData.getUserCount());
			}else if(banquetType == eBanquetType.CrossBanquet.getValue()){
				banquetTemp.setMemNum(CrossBanquetMgr.getBanquetMemberCount(banquetId));
			}
			if(syncReward){
				for(UserBanquetFeastReward info : infoMap.values()){
					BanquetProto.BanquetPopRewardListTemp.Builder temp = BanquetProto.BanquetPopRewardListTemp.newBuilder();
					temp.setRewardId(info.getRewardId());
					temp.setIsGetReward(info.isGetReward());
					banquetTemp.addRewardList(temp);
				}
			}
			msg.addBanquetList(banquetTemp);
		}
		return msg;
	}

	//刚进场景的同步用户
	public static BanquetProto.BanquetMemberSync.Builder parseBanquetMemberSyncResp(UserBanquetData userBanquetData,Map<Long,UserBanquetMember> userBanquetMemberMap,int count){
		BanquetProto.BanquetMemberSync.Builder msg = BanquetProto.BanquetMemberSync.newBuilder();
		msg.setBanquetId(userBanquetData.getBanquetId());
		msg.setPopularity(userBanquetData.getPopularity());
		msg.setCount(count);
		for(UserBanquetMember info : userBanquetMemberMap.values()){
			msg.addMemberList(parseBanquetMemberTempMsg(info));
		}
		return msg;
	}

	//用户参加宴会的单个同步
	public static BanquetProto.BanquetMemberSync.Builder parseBanquetMemberSyncResp(UserBanquetData userBanquetData,UserBanquetMember userBanquetMember,int count){
		BanquetProto.BanquetMemberSync.Builder msg = BanquetProto.BanquetMemberSync.newBuilder();
		msg.setBanquetId(userBanquetData.getBanquetId());
		msg.setPopularity(userBanquetData.getPopularity());
		msg.setCount(count);
		msg.addMemberList(parseBanquetMemberTempMsg(userBanquetMember));
		return msg;
	}

	//刚进场景的同步用户-跨服
	public static BanquetProto.BanquetMemberSync.Builder parseBanquetMemberSyncResp(UserCrossBanquetData crossBanquetData,Map<Long,CrossBanquetMember> banquetMember,int count){
		BanquetProto.BanquetMemberSync.Builder msg = BanquetProto.BanquetMemberSync.newBuilder();
		msg.setBanquetId(crossBanquetData.getBanquetId());
		msg.setPopularity(crossBanquetData.getPopularity());
		msg.setCount(count);
		for(CrossBanquetMember info : banquetMember.values()){
			msg.addMemberList(parseBanquetMemberTempMsg(info));
		}
		return msg;
	}

	//用户参加跨服宴会的单个同步
	public static BanquetProto.BanquetMemberSync.Builder parseBanquetMemberSyncResp(UserCrossBanquetData crossBanquetData, CrossBanquetMember banquetMember, int count){
		BanquetProto.BanquetMemberSync.Builder msg = BanquetProto.BanquetMemberSync.newBuilder();
		msg.setBanquetId(crossBanquetData.getBanquetId());
		msg.setPopularity(crossBanquetData.getPopularity());
		msg.setCount(count);
		//改成跨服宴会不同步了
		if(BanquetConfigMgr.isCrossUserBanquet(crossBanquetData.getType())){
			msg.addMemberList(parseBanquetMemberTempMsg(banquetMember));
		}
		return msg;
	}


	public static BanquetProto.BanquetGetRecordResp.Builder parseBanquetGetRecordResp(List<UserBanquetRecord> userBanquetRecordList){
		BanquetProto.BanquetGetRecordResp.Builder msg = BanquetProto.BanquetGetRecordResp.newBuilder();
		for(UserBanquetRecord info : userBanquetRecordList){
			if(BanquetConfigMgr.isCrossUserBanquet(info.getType())){
				CrossBanquetData crossBanquetData = JSON.parseObject(info.getRecord(), CrossBanquetData.class);
				msg.addRecordList(parseCrossUserBanquetRecordTempMsg(crossBanquetData));
			}else{
				UserBanquetData userBanquetData = JSON.parseObject(info.getRecord(),UserBanquetData.class);
				msg.addRecordList(parseBanquetRecordTempMsg(userBanquetData));
			}
		}
		return msg;
	}

	//把跨服的私人宴会转成记录
	public static UserBanquetRecord parseToBanquetRecord(CrossBanquetProto.SendCrossUserBanquetRecordMsg crossUserBanquetRecordMsg){
		UserBanquetRecord userBanquetRecord = new UserBanquetRecord();
		userBanquetRecord.setBanquetId(crossUserBanquetRecordMsg.getBanquetId());
		userBanquetRecord.setType(crossUserBanquetRecordMsg.getType());
		userBanquetRecord.setUserId(crossUserBanquetRecordMsg.getUserId());
		userBanquetRecord.setRecord(crossUserBanquetRecordMsg.getRecord());
		userBanquetRecord.setOpenTime(crossUserBanquetRecordMsg.getOpenTime());
		userBanquetRecord.setOverTime(crossUserBanquetRecordMsg.getOverTime());
		userBanquetRecord.setMemberCount(crossUserBanquetRecordMsg.getMemberCount());
		return userBanquetRecord;
	}

	public static BanquetProto.BanquetRecordTempMsg.Builder parseBanquetRecordTempMsg(UserBanquetData data){
		BanquetProto.BanquetRecordTempMsg.Builder msg = BanquetProto.BanquetRecordTempMsg.newBuilder();
		msg.setBanquetId(data.getBanquetId());
		msg.setType(data.getType());
		msg.setOpenTime((int)(data.getOpenTime()/1000));
		msg.setInfo(data.getInvitationInfo());
		msg.setUserId(data.getUserId());
		msg.setPopularity(data.getPopularity());
		msg.setIntegral(data.getIntegral());
		msg.setMemberCount(data.getUserCount());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(data.getUserBaseInfo());
		msg.setPlayerBaseData(baseMsg);
		for(UserBanquetMember member : data.getUserBanquetMemberMap().values()){
			msg.addMemberRewardList(parseMemberRewardTempMsg(member));
		}
		return msg;
	}

	public static BanquetProto.BanquetRecordTempMsg.Builder parseCrossUserBanquetRecordTempMsg(CrossBanquetData data){
		BanquetProto.BanquetRecordTempMsg.Builder msg = BanquetProto.BanquetRecordTempMsg.newBuilder();
		msg.setBanquetId(data.getBanquetId());
		msg.setType(data.getType());
		msg.setOpenTime((int)(data.getOpenTime()/1000));
		msg.setInfo(data.getInvitationInfo());
		msg.setUserId(data.getUserId());
		msg.setPopularity(data.getPopularity());
		msg.setIntegral(data.getIntegral());
		msg.setMemberCount(data.getUserCount());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(data.getUserBaseInfo());
		msg.setPlayerBaseData(baseMsg);
		for(CrossBanquetMember member : data.getMemberMap().values()){
			msg.addMemberRewardList(parseCrossMemberRewardTempMsg(member));
		}
		return msg;
	}

	public static BanquetProto.BanquetGetRewardResp.Builder parseBanquetGetRewardResp(Map<String, UserBanquetData> userBanquetDataMap){
		BanquetProto.BanquetGetRewardResp.Builder msg = BanquetProto.BanquetGetRewardResp.newBuilder();
		for(UserBanquetData info : userBanquetDataMap.values()){
			msg.addRewardList(parseBanquetGetRewardTempMsg(info));
		}
		return msg;
	}

	public static BanquetProto.BanquetGetRewardTempMsg.Builder parseBanquetGetRewardTempMsg(UserBanquetData userBanquetData){
		BanquetProto.BanquetGetRewardTempMsg.Builder msg = BanquetProto.BanquetGetRewardTempMsg.newBuilder();
		msg.setBanquetId(userBanquetData.getBanquetId());
		msg.setType(userBanquetData.getType());
		msg.setOpenTime((int)(msg.getOpenTime()/1000));
		msg.setInfo(userBanquetData.getInvitationInfo());
		msg.setPopularity(userBanquetData.getPopularity());
		msg.setIntegral(userBanquetData.getIntegral());
		msg.setChildEarnSpeed(userBanquetData.getChildAddEarnSpeed());
		msg.setReward(userBanquetData.getEndReward());
		msg.setMemCount(userBanquetData.getUserCount());
		for(UserBanquetMember member : userBanquetData.getUserBanquetMemberMap().values()){
			msg.addMemberRewardList(parseMemberRewardTempMsg(member));
		}
		return msg;
	}

	public static BanquetProto.MemberRewardTempMsg.Builder parseMemberRewardTempMsg(UserBanquetMember memberInfo){
		BanquetProto.MemberRewardTempMsg.Builder msg = BanquetProto.MemberRewardTempMsg.newBuilder();
		msg.setUserId(memberInfo.getUserId());
		msg.setPopularity(memberInfo.getPopularity());
		msg.setIntegral(memberInfo.getIntegral());
		msg.setIsRobot(memberInfo.isRobot());
		msg.setGiftId(memberInfo.getGiftId());
		msg.setRobotId(memberInfo.getRobotId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(memberInfo.getUserBaseInfo());
		msg.setPlayerBaseData(baseMsg);
		msg.setPos(memberInfo.getPos());
		return msg;
	}

	public static BanquetProto.MemberRewardTempMsg.Builder parseCrossMemberRewardTempMsg(CrossBanquetMember memberInfo){
		BanquetProto.MemberRewardTempMsg.Builder msg = BanquetProto.MemberRewardTempMsg.newBuilder();
		msg.setUserId(memberInfo.getUserId());
		msg.setPopularity(memberInfo.getPopularity());
		msg.setIntegral(memberInfo.getIntegral());
		msg.setIsRobot(memberInfo.isRobot());
		msg.setGiftId(memberInfo.getGiftId());
		msg.setRobotId(memberInfo.getRobotId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(memberInfo.getUserBaseInfo());
		msg.setPlayerBaseData(baseMsg);
		msg.setPos(memberInfo.getPos());
		return msg;
	}

	public static BanquetProto.SyncSelfBanquetMsg.Builder parseSyncSelfBanquet(GamePlayer player,List<UserBanquetData> userBanquetDataList){
		BanquetProto.SyncSelfBanquetMsg.Builder msg = BanquetProto.SyncSelfBanquetMsg.newBuilder();
		for(UserBanquetData info :userBanquetDataList){
			msg.addBanquetDataList(parseBanquetDataTempMsg(player,info));
		}
		return msg;
	}

	public static BanquetProto.BanquetJoinNoticeOwnerMsg.Builder parseBanquetJoinNoticeOwnerMsg(UserBanquetMember userBanquetMember){
		BanquetProto.BanquetJoinNoticeOwnerMsg.Builder msg = BanquetProto.BanquetJoinNoticeOwnerMsg.newBuilder();
		msg.setUserId(userBanquetMember.getUserId());
		msg.setPos(userBanquetMember.getPos());
		msg.setPopularity(userBanquetMember.getPopularity());
		msg.setGiftId(userBanquetMember.getGiftId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(userBanquetMember.getUserBaseInfo());
		msg.setPlayerBaseData(baseMsg);
		return msg;
	}

	public static BanquetProto.SyncSelfBanquetMsg.Builder parseSyncSelfCrossBanquet(GamePlayer player,List<UserCrossBanquetData> userBanquetDataList){
//		CrossBanquetProto.SyncSelfCrossBanquetMsg.Builder msg = CrossBanquetProto.SyncSelfCrossBanquetMsg.newBuilder();
//		for(UserCrossBanquetData info :userBanquetDataList){
//			msg.addBanquetDataList(parseCrossBanquetDataTempMsg(player,info));
//		}
		BanquetProto.SyncSelfBanquetMsg.Builder msg = BanquetProto.SyncSelfBanquetMsg.newBuilder();
		for(UserCrossBanquetData info : userBanquetDataList){
			msg.addBanquetDataList(parseBanquetDataTempMsgCross(player, info));
		}
		return msg;
	}

	public static BanquetProto.BanquetMemberInfoResp.Builder parseBanquetMemberListRespMsg(GamePlayer player,UserBanquetData banquetInfo,Map<Long,UserBanquetMember> userBanquetMemberMap,int count){
		BanquetProto.BanquetMemberInfoResp.Builder msg = BanquetProto.BanquetMemberInfoResp.newBuilder();
		msg.setBanquetInfo(parseBanquetDataTempMsg(player,banquetInfo));
		msg.setCount(count);
		for(UserBanquetMember info : userBanquetMemberMap.values()){
			msg.addMemberList(parseBanquetMemberTempMsg(info));
		}
		return msg;
	}

	public static CrossBanquetProto.CrossBanquetMemberInfoResp.Builder parseBanquetMemberListRespMsg(GamePlayer player,UserCrossBanquetData banquetInfo,Map<Long,CrossBanquetMember> userBanquetMemberMap,int count){
		CrossBanquetProto.CrossBanquetMemberInfoResp.Builder msg = CrossBanquetProto.CrossBanquetMemberInfoResp.newBuilder();
		msg.setBanquetInfo(parseCrossBanquetDataTempMsg(player,banquetInfo));
		msg.setCount(count);
		for(CrossBanquetMember info : userBanquetMemberMap.values()){
			msg.addMemberList(parseBanquetMemberTempMsg(info));
		}
		return msg;
	}

	private static BanquetProto.BanquetMemberTemp.Builder parseBanquetMemberTempMsg(UserBanquetMember info){
		BanquetProto.BanquetMemberTemp.Builder temp = BanquetProto.BanquetMemberTemp.newBuilder();
		temp.setUserId(info.getUserId());
		temp.setPos(info.getPos());
		temp.setPopularity(info.getPopularity());
		temp.setIsRobot(info.isRobot());
		temp.setRobotId(info.getRobotId());
		temp.setGiftId(info.getGiftId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(info.getUserBaseInfo());
		temp.setPlayerBaseData(baseMsg);
		return temp;
	}

	public static BanquetProto.BanquetMemberTemp.Builder parseBanquetMemberTempMsg(CrossBanquetMember info){
		BanquetProto.BanquetMemberTemp.Builder temp = BanquetProto.BanquetMemberTemp.newBuilder();
		temp.setUserId(info.getUserId());
		temp.setPos(info.getPos());
		temp.setPopularity(info.getPopularity());
		temp.setIsRobot(info.isRobot());
		temp.setRobotId(info.getRobotId());
		temp.setGiftId(info.getGiftId());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(info.getUserBaseInfo());
		temp.setPlayerBaseData(baseMsg);
		temp.setJoinTime(info.getJoinTime());
		return temp;
	}

	public static BanquetProto.BanquetFeastSync.Builder parseBanquetFeastListRespMsg(GamePlayer player,Map<String, UserBanquetData> userBanquetDataMap){
		BanquetProto.BanquetFeastSync.Builder msg = BanquetProto.BanquetFeastSync.newBuilder();
		for(UserBanquetData info : userBanquetDataMap.values()){
			if(info.getUserId() == player.getUserId()){
				continue;
			}
			msg.addBanquetDataList(parseBanquetDataTempMsg(player,info));
		}
		return msg;
	}

	public static CrossBanquetProto.BanquetCrossSync.Builder parseCrossBanquetListSyncMsg(GamePlayer player, Map<String, UserCrossBanquetData> userCrossBanquetDataMap){
		CrossBanquetProto.BanquetCrossSync.Builder msg = CrossBanquetProto.BanquetCrossSync.newBuilder();
		for(UserCrossBanquetData info : userCrossBanquetDataMap.values()){
			if(info.getUserId() == player.getUserId()){
				continue;
			}
			msg.addBanquetList(parseCrossBanquetDataTempMsg(player,info));
		}
		return msg;
	}

	public static CrossBanquetProto.CrossBanquetListResp.Builder parseCrossBanquetListRespMsg(GamePlayer player, Map<String, UserCrossBanquetData> userCrossBanquetDataMap){
		CrossBanquetProto.CrossBanquetListResp.Builder msg = CrossBanquetProto.CrossBanquetListResp.newBuilder();
		for(UserCrossBanquetData info : userCrossBanquetDataMap.values()){
			if(info.getUserId() == player.getUserId()){
				continue;
			}
			msg.addBanquetDataList(parseCrossBanquetDataTempMsg(player,info));
		}
		return msg;
	}

	public static CrossBanquetProto.CrossBanquetTemp.Builder parseCrossBanquetDataTempMsg(GamePlayer player,UserCrossBanquetData info){
		CrossBanquetProto.CrossBanquetTemp.Builder temp = CrossBanquetProto.CrossBanquetTemp.newBuilder();
		temp.setUserId(info.getUserId());
		temp.setBanquetId(info.getBanquetId());
		temp.setType(info.getType());
		temp.setOpenTime((int)(info.getOpenTime()/1000));
		temp.setPopularity(info.getPopularity());
		temp.setNum(info.getUserCount());
		temp.setOverTime((int)(info.getOverTime()/1000));
		temp.setInvitation(info.getInvitationInfo());
		temp.setGiftTypeAccept(info.getGiftTypeAccept());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(info.getUserBaseInfo());
		temp.setPlayerBaseData(baseMsg);
		if(CrossBanquetMgr.getBanquetMemberMap(info.getBanquetId(),0,0).containsKey(player.getUserId())){
			temp.setSelfJoin(true);
		}else{
			temp.setSelfJoin(false);
		}
//		temp.setServerId(info.getServerId());
//		temp.setServerList(info.getServerListStr());
		temp.setMessage(info.getMessage());
		return temp;
	}

	public static BanquetProto.BanquetListResp.Builder parseBanquetListRespMsg(GamePlayer player,Map<String, UserBanquetData> userBanquetDataMap){
		BanquetProto.BanquetListResp.Builder msg = BanquetProto.BanquetListResp.newBuilder();
		for(UserBanquetData info : userBanquetDataMap.values()){
			msg.addBanquetDataList(parseBanquetDataTempMsg(player,info));
		}
		return msg;
	}

	public static BanquetProto.BanquetListResp.Builder parseBanquetListRespMsgCross(GamePlayer player,Map<String, UserCrossBanquetData> userBanquetDataMap){
		BanquetProto.BanquetListResp.Builder msg = BanquetProto.BanquetListResp.newBuilder();
		for(UserCrossBanquetData info : userBanquetDataMap.values()){
			msg.addBanquetDataList(parseBanquetDataTempMsgCross(player,info));
		}
		return msg;
	}

	private static BanquetProto.BanquetTemp.Builder parseBanquetDataTempMsg(GamePlayer player,UserBanquetData info){
		BanquetProto.BanquetTemp.Builder temp = BanquetProto.BanquetTemp.newBuilder();
		temp.setUserId(info.getUserId());
		temp.setBanquetId(info.getBanquetId());
		temp.setType(info.getType());
		temp.setOpenTime((int)(info.getOpenTime()/1000));
		temp.setPopularity(info.getPopularity());
		temp.setNum(info.getUserCount());
		temp.setOverTime((int)(info.getOverTime() / 1000));
		//婚宴必须知道美女的亲密度
		if(info.getType() == eBanquetInfoType.MarryBanquet.getValue()){
			BanquetMarryInvitation inv = JSON.parseObject(info.getInvitationInfo(),BanquetMarryInvitation.class);
			GamePlayer owner = GamePlayerMgr.getOnlinePlayer(info.getUserId());
			if(owner != null){
				inv.setIntimacy(owner.getModule(BeautyModule.class).getUserBeauty(inv.getBeautyId()).getTotalIntimacy());
			}else{
				inv.setIntimacy(UserBeautyBussiness.getUserBeauty(info.getUserId(),inv.getBeautyId()).getTotalIntimacy());
			}
			info.setInvitationInfo(JSON.toJSONString(inv));
		}
		temp.setInvitation(info.getInvitationInfo());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(info.getUserBaseInfo());
		temp.setPlayerBaseData(baseMsg);
		if(BanquetMgr.getBanquetMemberMap(info.getBanquetId(),0,0).containsKey(player.getUserId())){
			temp.setSelfJoin(true);
		}else{
			temp.setSelfJoin(false);
		}
		if(BanquetMgr.isRelative(player,info.getUserId())){
			temp.setIsKinship(true);
		}else{
			temp.setIsKinship(false);
		}
		return temp;
	}

	public static BanquetProto.BanquetTemp.Builder parseBanquetDataTempMsgCross(GamePlayer player,UserCrossBanquetData info){
		BanquetProto.BanquetTemp.Builder temp = BanquetProto.BanquetTemp.newBuilder();
		temp.setUserId(info.getUserId());
		temp.setBanquetId(info.getBanquetId());
		temp.setType(info.getType());
		temp.setOpenTime((int)(info.getOpenTime()/1000));
		temp.setPopularity(info.getPopularity());
		temp.setNum(info.getUserCount());
		temp.setOverTime((int)(info.getOverTime()/1000));
		//婚宴必须知道美女的亲密度
		if(info.getType() == eBanquetInfoType.MarryBanquet.getValue()){
			BanquetMarryInvitation inv = JSON.parseObject(info.getInvitationInfo(),BanquetMarryInvitation.class);
			GamePlayer owner = GamePlayerMgr.getOnlinePlayer(info.getUserId());
			if(owner != null){
				inv.setIntimacy(owner.getModule(BeautyModule.class).getUserBeauty(inv.getBeautyId()).getTotalIntimacy());
			}else{
				inv.setIntimacy(UserBeautyBussiness.getUserBeauty(info.getUserId(),inv.getBeautyId()).getTotalIntimacy());
			}
			info.setInvitationInfo(JSON.toJSONString(inv));
		}
		temp.setInvitation(info.getInvitationInfo());
		PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(info.getUserBaseInfo());
		temp.setPlayerBaseData(baseMsg);
		Map<Long, CrossBanquetMember> memberMap = CrossBanquetMgr.getBanquetMemberMap(info.getBanquetId(), 0, 0);
		if(memberMap.containsKey(player.getUserId())){
			temp.setSelfJoin(true);
		}else{
			temp.setSelfJoin(false);
		}
		if(BanquetMgr.isRelative(player,info.getUserId())){
			temp.setIsKinship(true);
		}else{
			temp.setIsKinship(false);
		}
		if(BanquetConfigMgr.isCrossUserBanquet(info.getType())){
			temp.addAllJoinList(memberMap.keySet());
		}
		temp.setMessage(info.getMessage());
		temp.setGiftTypeAccept(info.getGiftTypeAccept());
		return temp;
	}

	public static BanquetProto.BanquetInvitationResp.Builder parseBanquetInvitationRespMsg(Map<String,UserBanquetInvitation> userBanquetInvitationMap){
		BanquetProto.BanquetInvitationResp.Builder msg = BanquetProto.BanquetInvitationResp.newBuilder();
		for(UserBanquetInvitation info : userBanquetInvitationMap.values()){
			msg.addInvitationList(parseBanquetInvitationTempMsg(info));
		}
		return msg;
	}

	public static BanquetProto.BanquetInvitationSync.Builder parseBanquetInvitationSyncMsg(Map<String,UserBanquetInvitation> userBanquetInvitationMap){
		BanquetProto.BanquetInvitationSync.Builder msg = BanquetProto.BanquetInvitationSync.newBuilder();
		for(UserBanquetInvitation info : userBanquetInvitationMap.values()){
			msg.addInvitationList(parseBanquetInvitationTempMsg(info));
		}
		return msg;
	}

	private static BanquetProto.BanquetInvitationTempMsg.Builder parseBanquetInvitationTempMsg(UserBanquetInvitation info){
		BanquetProto.BanquetInvitationTempMsg.Builder temp = BanquetProto.BanquetInvitationTempMsg.newBuilder();
		temp.setIId(info.getiId());
		temp.setType(info.getType());
		temp.setCreateTime((int)(info.getCreateTime()/1000));
		temp.setInfo(info.getInfo());
		temp.setOverTime(info.getOverTime() / 1000);
		return temp;
	}

	public static BanquetProto.BanquetRelationshipRespMsg.Builder parseBanquetRelationshipRespMsg(List<UserBanquetRelationship> dataMap){
		BanquetProto.BanquetRelationshipRespMsg.Builder resp = BanquetProto.BanquetRelationshipRespMsg.newBuilder();
		for(UserBanquetRelationship info : dataMap){
			BanquetProto.BanquetRelationshipTemp.Builder temp = BanquetProto.BanquetRelationshipTemp.newBuilder();
			temp.setUserId(info.getUserId());
			temp.setTo(info.getTo());
			temp.setFrom(info.getFrom());
			if(!StringUtils.isNullOrEmpty(info.getBanquetId())){
				temp.setBanquetId(info.getBanquetId());
			}
			UserBaseInfo userBaseInfo = UserMgr.getUserBaseInfo(info.getUserId(), GameServer.getInstance().getServerId());
			if(userBaseInfo != null){
				PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo);
				temp.setPlayerBaseData(baseMsg);
			}
			resp.addShipList(temp);
		}
		return resp;
	}

	public static BanquetProto.BanquetRelationshipRespMsg.Builder parseCrossBanquetRelationshipRespMsg(List<CrossPartyRelationship> dataMap) {
		BanquetProto.BanquetRelationshipRespMsg.Builder resp = BanquetProto.BanquetRelationshipRespMsg.newBuilder();
		for (CrossPartyRelationship info : dataMap) {
			BanquetProto.BanquetRelationshipTemp.Builder temp = BanquetProto.BanquetRelationshipTemp.newBuilder();
			temp.setUserId(info.getUserId());
			temp.setTo(info.getTo());
			temp.setFrom(info.getFrom());
			if (!StringUtils.isNullOrEmpty(info.getBanquetId())) {
				temp.setBanquetId(info.getBanquetId());
			}
			if (info.getUserBaseInfo() != null) {
				if (info.getUserBaseInfo() != null) {
					PlayerProto.PlayerBaseTempMsg.Builder baseMsg = PlayerBasePb.parsePlayerBaseTempMsg(info.getUserBaseInfo());
					temp.setPlayerBaseData(baseMsg);
				}
			}
			resp.addShipList(temp);
		}
		return resp;
	}

}
